package com.jtcl.module.service;

import com.jtcl.module.mapper.UserMapper;
import com.jtcl.module.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Auther: csp1999
 * @Date: 2020/12/02/17:31
 * @Description:
 */
@Service
public class UserService implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;


    public User findUserByName(String username) {
        return userMapper.selectByName(username);
    }

    /**
     * UserDetailsService 接口提供的根据用户名获取用户信息的方法
     *
     * @param username
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 调用我们自己的findUserByName 方法
        return this.findUserByName(username);
    }
}
